<?php
/**
* 根据模块id生成多选框代码
* @param id			模块id
* @param itemid		项目id
* @param inputname	表单名称
* @return String
*/
function getPInputHtml($id,$itemid,$inputname="couldview",$isChecked=0)
{
	if($isChecked==0)
	{
		$str='<input type="checkbox" name="'.$inputname.'" id="'.$inputname.'_'.$id.'" value="'.$id.'" itemid="'.$itemid.'">';
	}
	else
	{
		$str='<input type="checkbox" name="'.$inputname.'" id="'.$inputname.'_'.$id.'" value="'.$id.'" itemid="'.$itemid.'" checked>';
	}
	return $str;
}


/**
* @param inputname		表单名称
* @param strPermissions	权限字符串
* @return void
*/
function showPermissionsList($inputname="couldview",$strPermissions='')
{

	$aryPermissions=getPermissionsArray($strPermissions);
	$ss='<script language="javascript" src="js/myscript.js"></script>';
	$aryP1=getPermissionsByGrade();		//权限类别数组
	if(is_array($aryP1))
	{
		foreach($aryP1 as $key=>$value)
		{
			if(checkPermission_admin($value['permissions_id'],$aryPermissions))
			{
				$isChecked=1;
			}
			else
			{
				$isChecked=0;
			}
			$ss.='<a href="javascript:changeChecked(\''.$inputname.'\',\''.$value['permissions_id'].'\')">全选/全否</a><br><B>'.getPInputHtml($value['permissions_id'],$value['permissions_id'],$inputname,$isChecked).'<label for="'.$inputname.'_'.$value['permissions_id'].'" style=" cursor:pointer">'.$value['name'].'</label></B>'."<BR>\n";
			$aryP2=getPermissionsByPid($value['permissions_id']);
			$ss.=getPermissionsListByAry($aryP2,$value['permissions_id'],$inputname,$aryPermissions);
		}
	}
	echo $ss;
}

/**
* 根据权限内容定义
* @param aryPermission	权限信息数组
* @param strPermissions	权限字符串
* @return String
*/
function getPermissionsListByAry($aryPermission,$itemid,$inputname="couldview",$aryPermissions)
{
	$ss='';
	if(is_array($aryPermission))
	{
		foreach($aryPermission as $key => $value)
		{
			if(checkPermission_admin($value['permissions_id'],$aryPermissions))
			{
				$isChecked=1;
			}
			else
			{
				$isChecked=0;
			}
			$ss.='<label for="'.$inputname.'_'.$value['permissions_id'].'" style=" cursor:pointer"><div style="width:100px;float:left;margin-left:10px;">'.getPInputHtml($value['permissions_id'],$itemid,$inputname,$isChecked).$value['name'].'</B></div></label>';
		}
		$ss.="<br><br>"."\n";
	}
	return $ss;
}
?>